package org.jeecg.modules.rooms.service;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.rooms.Vo.SelectVo;
import org.jeecg.modules.rooms.entity.CesRoomPricePlan;
import org.jeecg.modules.rooms.mapper.CesRoomPricePlanMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fendo
 * @since 2023-03-02
 */
@Service
public class CesRoomPricePlanServiceImpl extends ServiceImpl<CesRoomPricePlanMapper, CesRoomPricePlan> implements IService<CesRoomPricePlan> {
    @Resource
    private CesRoomPricePlanMapper pricePlanMapper;

    /**
     * 获取当前酒店的房价方案
     * @param hotelId
     * @return
     */
    public Result getRoomPlans(String hotelId){
        List<CesRoomPricePlan> planList =  pricePlanMapper.selectList(Wrappers.<CesRoomPricePlan>lambdaQuery().eq(CesRoomPricePlan::getHotelId,hotelId).eq(CesRoomPricePlan::getInvalid,false));
        if(CollectionUtil.isEmpty(planList)) return Result.ok(new ArrayList<>());
        List<SelectVo> vos = new ArrayList<>();
        planList.forEach(v -> {
            SelectVo vo = new SelectVo();
            vo.setLabel(v.getName());
            vo.setValue(v.getId());
            vos.add(vo);
        });
        return Result.ok(vos);
    }
}
